package com.hps.demo.schedule;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

/**
 * @author heps
 * @date 2019/1/23 13:56
 */
public class ScheduledMessageProducer {

    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("group1");
        producer.setNamesrvAddr("192.168.26.137:9876");
        producer.start();
        for (int i = 0; i < 100; i++) {
            Message message = new Message("TestTopic",
                    "TagA",
                    ("Hello scheduled message " + i).getBytes(RemotingHelper.DEFAULT_CHARSET));

            // This message will be delivered to consumer 10 seconds later.
            message.setDelayTimeLevel(3);
            producer.send(message);
        }
        producer.shutdown();
    }
}
